"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
var app = getApp();
exports.default = Page({
  data: {},
  onLoad: function onLoad(e) {
    var _this = this;
    var mid = e.mid;
    var name = e.name;
    var price = e.price;
    var activity = e.activity;
    var openid = wx.getStorageSync("openid");
    _this.setData({
      mid: mid,
      name: name,
      price: price,
      activity: activity,
      openid: openid
    });
  },
  pay: function pay(e) {
    var _this = this;
    var mid = e.currentTarget.dataset.mid;
    var price = e.currentTarget.dataset.price;
    wx.request({
      url: app.globalData.host,
      data: {
        mod: "record",
        act: "pay",
        ssid: _this.data.openid,
        mid: mid
      },
      method: "post", // OPTIONS, GET, HEAD, POST, PUT, DELETE, TRACE, CONNECT
      header: {
        "Content-Type": "application/x-www-form-urlencoded"
      },
      success: function success(res) {
        // success
        console.log(res);
        var oid = res.data.info.oid;
        var amount = res.data.info.amount;
        var openid = _this.data.openid;
        wx.request({
          url: app.globalData.WxHost + "ssid=" + openid + "&mid=" + oid + "&money=" + amount,
          success: function success(response) {
            console.log(response);
            wx.requestPayment({
              appId: response.data.appId,
              nonceStr: response.data.nonceStr,
              timeStamp: response.data.timeStamp,
              package: response.data.package,
              signType: response.data.signType,
              paySign: response.data.paySign,
              success: function success(result) {
                console.log(result);
                wx.showToast({
                  title: "支付成功！",
                  icon: "none",
                  duration: 1000,
                  mask: false
                });
              },
              fail: function fail(result) {
                console.log(result);
                wx.showToast({
                  title: "支付失败！",
                  icon: "none",
                  duration: 1000,
                  mask: false
                });
              }
            });
          }
        });
      },
      fail: function fail() {
        // fail
      },
      complete: function complete() {
        // complete
      }
    });
  }
});